clear
set more off

local path0="C:\Dropbox\GeneticsProject (1)\REStat\round_accepted_replication_files\"


cd "`path0'\Workfiles"

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

use "`path0'\Data\Blood\data_nomi.dta"
drop if countrycode==""
joinby countrycode using "`path0'\Data\Blood\data_wiki.dta", unmatched(both)
tab _merge
drop if countrycode==""
drop _merge
joinby countrycode using "`path0'\Data\Blood\data_bloodbook.dta", unmatched(both)
tab _merge
drop if countrycode==""
drop _merge

rename bloodanomi bloodA_nomi 
rename bloodbnomi bloodB_nomi
rename bloodonomi bloodO_nomi
rename bloodawiki bloodA_wiki
rename bloodbwiki bloodB_wiki
rename bloodowiki bloodO_wiki
rename bloodobb bloodO_bb
rename bloodabb bloodA_bb
rename bloodbbb bloodB_bb

gen bloodA_wikiM = 1-sqrt(bloodB_wiki+bloodO_wiki)
gen bloodB_wikiM = 1-sqrt(bloodA_wiki+bloodO_wiki)
gen bloodO_wikiM = sqrt(bloodO_wiki)

gen bloodA_nomiM = 1-sqrt(bloodB_nomi+bloodO_nomi)
gen bloodB_nomiM = 1-sqrt(bloodA_nomi+bloodO_nomi)
gen bloodO_nomiM = sqrt(bloodO_nomi)

gen bloodA_bbM = 1-sqrt(bloodB_bb+bloodO_bb)
gen bloodB_bbM = 1-sqrt(bloodA_bb+bloodO_bb)
gen bloodO_bbM = sqrt(bloodO_bb)

drop bloodB_bb bloodA_bb bloodO_bb
drop bloodB_nomi bloodA_nomi bloodO_nomi 
drop bloodB_wiki bloodA_wiki bloodO_wiki 

rename bloodA_wikiM bloodA_wiki
rename bloodB_wikiM bloodB_wiki
rename bloodO_wikiM bloodO_wiki

rename bloodA_bbM bloodA_bb
rename bloodB_bbM bloodB_bb
rename bloodO_bbM bloodO_bb

rename bloodA_nomiM bloodA_nomi
rename bloodB_nomiM bloodB_nomi
rename bloodO_nomiM bloodO_nomi

label var bloodA_nomi "Blood type A: source Nomi book"
label var bloodB_nomi "Blood type B: source Nomi book"
label var bloodO_nomi "Blood type O: source Nomi book"
label var bloodA_wiki "Blood type A: source wikipedia"
label var bloodB_wiki "Blood type B: source wikipedia"
label var bloodO_wiki "Blood type O: source wikipedia"
label var bloodO_bb "Blood type O: source bloodbook"
label var bloodA_bb "Blood type A: source bloodbook"
label var bloodB_bb "Blood type B: source bloodbook"

egen tt=fill(1(1)10)
drop if countrycode=="GBR" & tt==43

drop tt

compress
save data_blood_alternative_sources, replace
